package com.situ.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.springboot.mapper.BlogTypeMapper;
import com.situ.springboot.pojo.BlogType;
import com.situ.springboot.pojo.query.BlogTypeQuery;
import com.situ.springboot.pojo.vo.BlogCountVO;
import com.situ.springboot.service.IBlogTypeService;
import com.situ.springboot.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

// Alt+Enter
@Service
public class BlogTypeServiceImpl implements IBlogTypeService {
    @Autowired
    private BlogTypeMapper blogTypeMapper;

    @Override
    public List<BlogType> selectAll() {
        return blogTypeMapper.selectAll();
    }

    @Override
    public List<BlogCountVO> blogCount() {
        return blogTypeMapper.blogCount();
    }

    @Override
    public PageResult list(BlogTypeQuery blogTypeQuery) {
        //开启分页
        PageHelper.startPage(blogTypeQuery.getPage(), blogTypeQuery.getLimit());
        //1、查找当前页的数据
        List<BlogType> list = blogTypeMapper.list(blogTypeQuery);
        //2、查询总的数量
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();

        return new PageResult(0, "", totalCount, list);
    }

    @Override
    public void deleteById(Integer id) {
        blogTypeMapper.deleteById(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        // delete from student where id in(1,2,34)
        for (Integer id : ids) {
            blogTypeMapper.deleteById(id);
        }
    }

    @Override
    public void add(BlogType blogType) {
        blogTypeMapper.add(blogType);
    }

    @Override
    public BlogType selectById(Integer id) {
        return blogTypeMapper.selectById(id);
    }

    @Override
    public void update(BlogType blogType) {
        blogTypeMapper.update(blogType);
    }
}
